﻿using System;
using System.Collections.ObjectModel;
using System.Data;
using System.Data.SqlClient;
using Entities;
using Common.Helper;

namespace DataAccess
{
    public class FacilityDao
    {
        /// <summary>
        /// Gets the instance.
        /// </summary>
        /// <value>
        /// The instance.
        /// </value>
        public static FacilityDao Instance { get; private set; }

        /// <summary>
        /// Initializes the <see cref="AddressDataAccess" /> class.
        /// </summary>
        static FacilityDao() { Instance = new FacilityDao(); }

        /// <summary>
        /// Extracts the raw data.
        /// </summary>
        /// <param name="dataReader">The data reader.</param>
        /// <returns></returns>
        private static Facility ExtractRawData(IDataReader dataReader)
        {

            var facility = new Facility {Active = (bool) dataReader["Active"]};

            return facility;
        }

        /// <summary>
        /// Inserts the specified facility.
        /// </summary>
        /// <param name="facility">The facility.</param>
        /// <returns></returns>
        public bool Insert(Facility facility)
        {
            var colParameter = new Collection<SqlParameter>();
            return SqlHelper.ExecuteNonQuery("procedureName", colParameter) > 0;

        }

        /// <summary>
        /// Updates the specified facility.
        /// </summary>
        /// <param name="facility">The facility.</param>
        /// <returns></returns>
        public bool Update(Facility facility)
        {
            var colParameter = new Collection<SqlParameter>();
            return SqlHelper.ExecuteNonQuery("procedureName", colParameter) > 0;
        }

        /// <summary>
        /// Gets the by id.
        /// </summary>
        /// <param name="facilityId">The facility id.</param>
        /// <returns></returns>
        public Facility GetById(Guid facilityId)
        {
            var colParameter = new Collection<SqlParameter>
                                   {
                                       new SqlParameter("facilityId", facilityId)
                                      
                                       
                                   };
            using (var reader = SqlHelper.ExecuteReader("GetById", colParameter))
            {
                if (reader.Read())
                {
                    return ExtractRawData(reader);

                }
                return null;
            }

        }

        /// <summary>
        /// Marks the inactive.
        /// </summary>
        /// <param name="facilityId">The facility id.</param>
        /// <returns></returns>
        public bool MarkInactive(Guid facilityId)
        {
            var colParameter = new Collection<SqlParameter>();
            return SqlHelper.ExecuteNonQuery("procedureName", colParameter) > 0;
        }

        /// <summary>
        /// Marks the acvite.
        /// </summary>
        /// <param name="facilityId">The facility id.</param>
        /// <returns></returns>
        public bool MarkAcvite(Guid facilityId)
        {
            var colParameter = new Collection<SqlParameter>();
            return SqlHelper.ExecuteNonQuery("procedureName", colParameter) > 0;
        }

        /// <summary>
        /// Lists the facility by premise.
        /// </summary>
        /// <param name="premise">The premise.</param>
        /// <param name="isActive">if set to <c>true</c> [is active].</param>
        /// <returns></returns>
        public Collection<Facility> ListFacilityByPremise(string premise, bool isActive)
        {
            var listAction = new Collection<Facility>();
            var colParameter = new Collection<SqlParameter>();
            using (var reader = SqlHelper.ExecuteReader("GetById", colParameter))
            {
                if (reader.Read())
                {
                    listAction.Add(ExtractRawData(reader));

                }
                return listAction;
            }

        }
        /// <summary>
        /// Orders the by lead contact by premise.
        /// </summary>
        /// <param name="premise">The premise.</param>
        /// <param name="isActive">if set to <c>true</c> [is active].</param>
        /// <returns></returns>
        public Collection<Facility> OrderByLeadContactByPremise(string premise, bool isActive)
        {
            var listAction = new Collection<Facility>();
            var colParameter = new Collection<SqlParameter>();
            using (var reader = SqlHelper.ExecuteReader("GetById", colParameter))
            {
                if (reader.Read())
                {
                    listAction.Add(ExtractRawData(reader));

                }
                return listAction;
            }

        }
        /// <summary>
        /// Orders the by room host by premise.
        /// </summary>
        /// <param name="premise">The premise.</param>
        /// <param name="isActive">if set to <c>true</c> [is active].</param>
        /// <returns></returns>
        public Collection<Facility> OrderByRoomHostByPremise(string premise, bool isActive)
        {
            var listAction = new Collection<Facility>();
            var colParameter = new Collection<SqlParameter>();
            using (var reader = SqlHelper.ExecuteReader("GetById", colParameter))
            {
                if (reader.Read())
                {
                    listAction.Add(ExtractRawData(reader));

                }
                return listAction;
            }

        }
    }
}
